<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import kuailiBanner from '@/api/kuaili/kuailiBanner'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()


const numberOperation = (newValue, id, numberName) => {
  kuailiBanner.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  kuailiBanner.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'kuaili_banner',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: kuailiBanner.getList,
  recycleApi: kuailiBanner.getRecycleList,
  add: {
    show: true,
    api: kuailiBanner.save,
    auth: ['kuaili:banner:save']
  },
  edit: {
    show: true,
    api: kuailiBanner.update,
    auth: ['kuaili:banner:update']
  },
  delete: {
    show: true,
    api: kuailiBanner.deletes,
    auth: ['kuaili:banner:delete'],
    realApi: kuailiBanner.realDeletes,
    realAuth: ['kuaili:banner:realDeletes']
  },
  recovery: {
    show: true,
    api: kuailiBanner.recoverys,
    auth: ['kuaili:banner:recovery']
  }
})

const columns = reactive([
  {
    title: "主键",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入主键"
    }
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "更新者",
    dataIndex: "updated_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "备注",
    dataIndex: "remark",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "图片",
    dataIndex: "image",
    formType: "upload",
    commonRules: {
      required: true,
      message: "请输入图片"
    },
    type: "image",
    multiple: false
  },
  {
    title: "排序",
    dataIndex: "sort",
    formType: "input-number",
    commonRules: {
      required: true,
      message: "请输入排序"
    },
    min: 0,
    max: 100,
    step: 1,
    precision: 0
  },
  {
    title: "状态",
    dataIndex: "status",
    formType: "radio",
    search: true,
    commonRules: {
      required: true,
      message: "请输入状态"
    },
    multiple: false,
    dict: {
      name: "data_status",
      props: {
        label: "title",
        value: "key"
      },
      translation: true
    }
  }
])
</script>
<script> export default { name: 'kuaili:banner' } </script>